package com.smart.community.user.enums;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;

/**
 * 状态枚举
 * 
 * @author Wu.Liang
 */
public enum StatusEnum {
    DISABLED(0, "禁用"),
    ENABLED(1, "启用");
    
    @JsonValue
    private final Integer code;
    private final String name;
    
    StatusEnum(Integer code, String name) {
        this.code = code;
        this.name = name;
    }
    
    public Integer getCode() {
        return code;
    }
    
    public String getName() {
        return name;
    }
    
    public static boolean isEnabled(Integer status) {
        return ENABLED.getCode().equals(status);
    }
    
    public static String getNameByCode(Integer code) {
        if (code == null) return "未知";
        for (StatusEnum status : values()) {
            if (status.getCode().equals(code)) {
                return status.getName();
            }
        }
        return "未知";
    }
    
    public static StatusEnum getByCode(Integer code) {
        if (code == null) return null;
        for (StatusEnum status : values()) {
            if (status.getCode().equals(code)) {
                return status;
            }
        }
        return null;
    }
    
    /**
     * Jackson反序列化方法
     * 严格遵循《系统状态枚举权威标准声明.md》规范
     * 
     * @param code 枚举值
     * @return 对应的枚举，如果不存在则返回null
     */
    @JsonCreator
    public static StatusEnum fromCode(Integer code) {
        return getByCode(code);
    }
} 